package cn.jsp.spring.reflect;

import cn.jsp.spring.domain.Stu;
import lombok.Data;

import java.lang.reflect.Field;

@Data
class SimpleObj{
  int age;
}
public class ReflectDemo {
  public static void main(String[] args) throws Exception {
    Class<SimpleObj> clazz= SimpleObj.class;
    Object obj=clazz.getDeclaredConstructor().newInstance();//new SimpleObj()
    Field[] fields=clazz.getDeclaredFields();//得到所有的变量 赋值或得到值
    for(Field f:fields){
      Object val=f.get(obj);
      System.out.println(val);
      f.set(obj,21);
    }
    System.out.println(obj);
  }
}
